package com.ys.controller.api.storage;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ys.entity.amazonorder.TpAmazonShopOrder;
import com.ys.entity.storage.TccStockControlHistory;
import com.ys.entity.sys.YsCol;
import com.ys.enume.sys.YsColEnum;
import com.ys.service.sys.CommonApiService;
import com.ys.service.sys.UploadService.UploadDto;
import com.ys.util.ExportExcelUtils;
import com.ys.vo.LayuiTableVoJA;
import com.ys.vo.R;

@Controller
@RequestMapping("/api/inter/tccStockControlHistory")
public class ApiInterTccStockControlHistoryController {
	
	private static Long MENU_ID = 18L; // TODO
	
//	private static final Logger logger = Logger.getLogger(ApiAdminLoginController.class);
	
	@Autowired
	private CommonApiService<TccStockControlHistory> commonApiService;
//	@Autowired
//	private TccStockControlHistoryService tpFbaPlanOrderService;

//	@RequiresPermissions("tpFbaPlanOrder:view")
	@RequestMapping("/search")
    @ResponseBody
	public LayuiTableVoJA search(Model model, HttpServletRequest request, HttpServletResponse response,
			@ModelAttribute TccStockControlHistory cond,
			String conditions
			){
//		
//		cond.addField("B.VGsJc vGsJc,B.GDepot locationArea,B.VKq locationKq,B.VHw vHw,B.ProductCode code,B.ProductName name");
//		cond.setOrderby("A.createTime desc");
//		cond.addLeftJoin("TCC_StockControl B on B.Guid = A.GuidStockControl");
		
		return commonApiService.searchLay(cond);
	}
	
//	@RequestMapping("/dtree")
//    @ResponseBody
//	public DtreeSqlDto dtree(Model model, HttpServletRequest request, HttpServletResponse response
//			){
//		return tpFbaPlanOrderService.dtree();
//	}
	
//	/*
//	 * 彻底删除
//	 */
//	@PostMapping("/deleteTrue")
//	@ResponseBody
//	public R deleteTrue(HttpServletRequest request, HttpServletResponse response,
//			Long id) {
//		return tpFbaPlanOrderService.deleteTrue(id);
//	}
//	
//	/**
//	 * 新增
//	 */
//	@PostMapping("/add")
//    @ResponseBody
//	public R add(HttpServletRequest request, @RequestParam Map<String, Object> params){
//		return tpFbaPlanOrderService.add(params);
//	}
//	
//	/**
//	 * 修改
//	 */
//	@PostMapping("/edit")
//    @ResponseBody
//	public R edit(HttpServletRequest request, @RequestParam Map<String, Object> params){
//		return tpFbaPlanOrderService.edit(params);
//	}
	
	@RequestMapping("/export")
    @ResponseBody
    public R export(@ModelAttribute TccStockControlHistory cond, String conditions) throws Exception{
		
		cond.setPage(0).setSize(999999);
		
		List<Map<String, Object>> listData = cond.queryMap();
        
    	List<YsCol> listField = new YsCol()
    			.setMenuId(MENU_ID)
    			.setFrontShow(YsColEnum.FrontShow.SHOW.value)
    			.setOrderby("A.SortNo asc")
    			.queryList();
    	
    	
        ExportExcelUtils<TpAmazonShopOrder> util = new ExportExcelUtils<TpAmazonShopOrder>(new TpAmazonShopOrder());
        
        String toFilePath = util.exportExcel(listData, listField, "历史库存状况表");
        UploadDto dto = commonApiService.uploadLocalToServer(toFilePath);
        return R.ok(dto.getUrl());
    }
	
}
